<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function ajax(options) {
            var { type = "get", url, data = "", async = "true", dataType = "text", success } = options;
            if (typeof data == "object") {
                var arr = [];
                for (var key in data) {
                    var val = data[key];
                    arr.push(key + "=" + val);
                }
                data = arr.join("&");
            }
            var xhr = new XMLHttpRequest();
            if (type.toLowerCase() == "post") {
                xhr.open(type, url, async);
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xhr.send(data);
            } else if (type.toLowerCase() == "get") {
                xhr.open(type, url + "?" + data, async);
                xhr.send();
            }

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var result = xhr.responseText;
                    if (dataType.toLowerCase() == "json") {
                        result = JSON.parse(result);
                    }
                    if (success) {
                        success(result);
                    }
                }
            }
        }
        ajax({
            type: "get",
            url: "../day6/php/html/php/isExist.php",
            data: { user: "a12345", pwd: "a12345", phone: "13455555555", email: "123445@qq.com" },
            async: "true",
            dataType: "json",
            success: function success(result) {
                console.log(result);
            }
        })
    </script>
</body>

</html>